<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>匹配所有单选按钮</title>
		<style>
			*{
				font-size: 14px;
				font-family: "微软雅黑";
				margin-top: 10px;
			}
			
			label{
				display: block;
				font-size: 14px;
				background-color: #ef5b00;
				color: white;
				height: 30px;
				line-height: 30px;
				text-align: left;
				display: block;
				cursor: pointer;
				width: 350px;
				font-family: "微软雅黑";
				/*去掉边框的关键代码*/
				border: 0 none;
			}
			label:hover{
				cursor: pointer;
			}
			
			.r{
				border: 3px solid red;
			}
		</style>
	</head>
	<body>
		 <form id="chk">
			星期：
			<input type="checkbox" name="newsletter" checked="checked" value="1" xx="1" />1
			<input type="checkbox" name="newsletter" value="2"  xx="2"/>2
			<input type="checkbox" name="newsletter" checked="checked" value="3" xx="3" />3
			<input type="checkbox" name="newsletter" value="4" xx="4" />4
			<input type="checkbox" name="newsletter" checked="checked" value="5" xx="5" />5
			<input type="checkbox" name="newsletter" value="6" xx="6" />6
			<input type="checkbox" name="newsletter" checked="checked" value="7" xx="7" />7
		</form>
		  
	
		全&nbsp;&nbsp;选： <input type="checkbox" id="selectAll">
		<br>
		全不选： <input type="checkbox" id="deleteAll">
		<br>
		反&nbsp;&nbsp;选： <input type="checkbox" id="invertSelect">
		<br>
			
	</form>
	</body>
	<!--Step1:导入jquery-->
	<script type="text/javascript" src="../../../js/jquery-1.4.1.js" ></script>
	<script>
		$("#selectAll").click(function(){
			$("#chk input:checkbox").attr("checked","checked");
		});
		
		$("#deleteAll").click(function(){
			$("#chk input:checkbox").removeAttr("checked");
		});
		
		$("#invertSelect").click(function(){
			var $cks = $("#chk input:checkbox");
			$cks.each(function(){
				
				console.log($(this).attr("checked"));
				if($(this).attr("checked")){
					//$(this).removeAttr("checked");
					$(this).attr("checked", false);
				}else{
					$(this).attr("checked",true);
					//$(this).attr("checked","checked");
				}
			});
		});
		
		$("#invertSelect2").click(function(){
			var $cks = $("#chk input:checkbox");
			for(var i=0;i<$cks.length;i++){
				var $ck = $cks.get(i);
				$ck.checked= !$ck.checked;
				console.log($ck.value + $ck.checked);
			}
		});
	</script>
</html>

